<div id="DialogTimeBulider">
    <p>
        这是计划任务时间表达式生成器</p>
    <small>旨在简化计划任务时间表达式的书写，十分简单</small>
    <hr>
    <div class="input-group input-group-sm">
        <span class="input-group-addon" id="sizing-addon3">每隔时间</span>
        <input id="DialogSec" type="text" class="form-control" placeholder="单位分钟，每隔多久执行 | 列如 60 代表一个小时" aria-describedby="sizing-addon3"
            v-model="sec">
    </div>
    <div class="input-group input-group-sm">
        <span class="input-group-addon" id="sizing-addon3">执行次数</span>
        <input id="DialogCount" type="text" class="form-control" placeholder="0 代表无限，其他正整数代表次数" v-model="count" aria-describedby="sizing-addon3">
    </div>
    <div class="input-group input-group-sm">
        <span class="input-group-addon" id="sizing-addon3">执行指令</span>
        <input id="DialogCommand" type="text" class="form-control" placeholder="与控制台命令一样，不要加 \ 符号" v-model="command" aria-describedby="sizing-addon3">
    </div>
    <p>填写好您需要的计划数据，单击 "生成" 再进行保存即可。</p>
    <button class="btn btn-success" v-on:click="ok()">
        生成
    </button>
    <button class="btn btn-danger" v-on:click="no()">
        取消
    </button>

</div>

<script>
    new Vue({
        el: "#DialogTimeBulider",
        data: {
            sec: "",
            count: "",
            command: ""
        },
        methods: {
            ok: function () {
                var time = this.sec;
                var h = 0;
                var d = 0;
                var mf = 0;
                while (time >= 60) {
                    h++;
                    time -= 60;
                    if (mf == 0) mf = 1;
                    if (h >= 24) {
                        d++;
                        h -= 24;
                        mf = 2;
                    };
                    if (d > 32) {
                        console.log("时间太长，不建议设置")
                        return;
                    }
                }
                var reg = "0 " + (mf == 0 ? "*/" : "") + time +
                    " " + (mf == 1 ? "*/" + h : mf == 0 ? "*" : h) +
                    " */" + d +
                    " * *";
                reg = reg.replace(/\*\/0/igm, "*");
                reg = reg.replace(/\_0/igm, "*");
                console.log("生成的时间表达式是:", reg)

                TOOLS.popWindClose({
                    time: reg,
                    count: this.count,
                    command: this.command
                });
            },
            no: function () {
                TOOLS.popWindClose(null);
            }
        }
    });
</script>